﻿using System;

namespace Aker.Sistem
{
    public class Barkod
    {
        public Barkod()
        {
        }

        public Barkod(int kod)
        {
            this.Kod = kod;
        }

        public enum BarkodTip
        {
            Artikel,
            Raf,
            Top,
            Elyaf,
            İplik
        }

        private int kod;
        public int Kod
        {
            get { return kod; }
            set
            {
                kod = value;
                if (kod > 0 && kod < 1000001)
                    Tip = BarkodTip.Artikel;
                else if (kod > 1000000 && kod < 2000001)
                    Tip = BarkodTip.Raf;
                else if (kod > 2000000 && kod < 3000001)
                    Tip = BarkodTip.Top;
                else if (kod > 5000000 && kod < 8000001)
                    Tip = BarkodTip.Elyaf;
                else if (kod > 8000000 && kod < 10000001)
                    Tip = BarkodTip.İplik;
            }
        }

        public BarkodTip Tip { get; set; }

        public int SembolKodu { get; set; }
        private DateTime tarih;

        public DateTime Tarih
        {
            get { return tarih; }
            set { tarih = value; }
        }

        public void SetTarih(byte[] Time)
        {
            int year = 1900;
            year += Time[0];

            int month = 1;
            month += Time[1];

            int day = Time[2];

            int hours = Time[3];

            int minutes = Time[4];

            int seconds = Time[5];

            //A.	1st Byte : years since 1900
            //B.	2nd Byte : months since January - [0,11]
            //C.	3rd Byte : day of the month - [1,31]
            //D.	4th Byte : hours since midnight - [0,23]
            //E.	5th Byte : minutes after the hour - [0,59]
            //F.	6th Byte : seconds after the minute - [0,59]
            //G.	7th Byte : days since Sunday - [0,6]


            if (year < 2000)
                year = 2000;

            tarih = new DateTime(year, month, day, hours, minutes, seconds);
        }

        public string Hata { get; set; }
    }
}